package com.cmcc.linlaker.ui.mine;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.cmcc.linlaker.R;
import com.cmcc.linlaker.http.ApiDefine;
import com.cmcc.linlaker.ui.mine.adapter.BookPageAdapter;
import com.cmcc.linlaker.ui.mine.bean.BookBean;
import com.cmcc.linlaker.ui.mine.bean.BookTypeBean;
import com.cmcc.linlaker.ui.mine.fragment.BookFragment;
import com.cmcc.linlaker.utils.BarUtils;
import com.cmcc.linlaker.volley.GsonRequestHelper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BookDetailActivity extends AppCompatActivity {
    private BookBean.BookListBean bookBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_book_detail);

        BarUtils.initStatusBar(this);

        bookBean = (BookBean.BookListBean) getIntent().getSerializableExtra("bookBean");

        initView();
    }

    private TextView text_name, text_date;
    private WebView mWebView;

    private void initView() {
        text_name = findViewById(R.id.text_name);
        text_date = findViewById(R.id.text_date);
        mWebView = findViewById(R.id.webView);
        mWebView.getSettings().setJavaScriptEnabled(true);  //可以夹杂javaScript
        mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); //设置允许js弹出alert对话框。
        mWebView.getSettings().setBuiltInZoomControls(true);//是否可以显示缩放按钮，默认是false
        mWebView.getSettings().setUseWideViewPort(true);//设置此属性，可任意比例缩放，大视图模式
        mWebView.getSettings().setLoadWithOverviewMode(true);//和setUseWideViewPort(true)一起解决网页自适应问题
        mWebView.getSettings().setAppCacheEnabled(true);//是否使用缓存
        mWebView.getSettings().setDomStorageEnabled(true);//DOM Storage
        //  mWebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);  //设置 缓存模式
        mWebView.getSettings().setPluginState(WebSettings.PluginState.ON); //播放视频
        mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); //设置不用缓存
        mWebView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        mWebView.getSettings().setGeolocationEnabled(true); //设置可以定位

        mWebView.getSettings().setSupportZoom(true);//是否可以缩放，默认是true
        mWebView.getSettings().setTextZoom(150);
        mWebView.getSettings().setTextSize(WebSettings.TextSize.LARGEST);

        text_name.setText(bookBean.name);
        text_date.setText(bookBean.createBy + "  " + bookBean.createTime);
        String content = bookBean.contant.replace("<img", "<img style='max-width:100%;height:auto'");
        mWebView.loadDataWithBaseURL("", Html.fromHtml(content).toString(), "text/html", "UTF-8", "");
//        mWebView.loadData(Html.fromHtml(bookBean.contant).toString(), "text/html", "UTF-8");
    }

    public void back(View view) {
        finish();
    }


}
